<template>
  <div class="container">
    <van-sticky :offset-top="0">
      <van-nav-bar left-text="返回" left-arrow @click-left="back" />
    </van-sticky>
    <div style="border-bottom: 0.4rem #ccc solid">
      <span>收件人：{{ list.user.nickName }}</span
      ><span style="float: right">手机：{{ list.user.userName }}</span>
      <p style="margin-top: 0.4rem">收货地址：{{ list.user.address }}</p>
    </div>
    <van-card
      v-for="item in list.details"
      :key="item.id"
      :num="item.amount"
      :price="item.price"
      desc="好的东西值得拥有"
      :title="item.product.name"
      :thumb="item.product.coverImage"
    />
    <p class="yun">运费<span style="float: right">+9.00</span></p>
    <p class="yun">
      小计<span style="float: right">￥{{ list.price + 9 }}</span>
    </p>
    <van-field
      style="margin-top: 1rem"
      v-model="message"
      rows="2"
      autosize
      label="评论"
      type="textarea"
      maxlength="50"
      placeholder="请输入评论"
      show-word-limit
    />
    <van-button
      type="danger"
      size="mini"
      style="float: right; margin-right: 0.5rem"
      @click="fcom()"
      >发布</van-button
    >
    <div>
      <ul class="mess">
        <li v-for="item in Mlist" :key="item.id">
          {{ item.content
          }}<span style="float: right; font-size: 0.5rem">{{
            $moment(item.createdAt).format("YYYY-MM-DD")
          }}</span>
        </li>
      </ul>
    </div>

    <van-submit-bar
      :price="(list.price + 9) * 100"
      button-text="立即支付"
      tip-icon="info-o"
      @submit="onSubmit"
    />
  </div>
</template>

<script>
import { orderdetail } from "../services/order";
import { fabu } from "../services/comment";
import { loadcomment } from "../services/comment";
import { Toast } from "vant";
export default {
  data() {
    return {
      list: [],
      message: "",
      Mlist: [],
    };
  },
  async created() {
    const res = await orderdetail(this.$route.query.id);
    this.list = res.data;
    console.log(res);
    this.loadCom();
  },
  methods: {
    back() {
      window.history.go(-1);
    },
    async fcom() {
      if (this.message) {
        const res = await fabu(this.list.details[0].product.id, this.message);
        console.log(res);
        this.message = "";
        this.loadCom();
      } else {
        Toast.fail("请输入内容");
      }
    },
    async loadCom() {
      const res = await loadcomment(this.list.details[0].product.id);
      console.log(res.data);
      this.Mlist = res.data.reverse();
    },
    onSubmit() {},
  },
};
</script>

<style scoped>
.container {
  padding: 0.2rem 0.6rem;
  margin-bottom: 2rem;
}
.yun {
  color: #999;
  margin-top: 0.6rem;
  line-height: 1.8rem;
  border-bottom: 1px solid #ccc;
}
.mess {
  margin-top: 3rem;
}
.mess li {
  margin: 1rem;
  border: 1px solid #cccc;
  height: 2rem;
  line-height: 2rem;
  text-indent: 5px;
  color: #333;
  font-size: 13px;
}
</style>